package logic

import (
	"context"
	"fmt"
	"goods_srv/models/es"

	"goods_srv/goodssrv"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsSearchLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsSearchLogic {
	return &GoodsSearchLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsSearchLogic) GoodsSearch(in *goodssrv.GoodsSearchRequest) (*goodssrv.GoodsSearchResponse, error) {
	// todo: add your logic here and delete this line
	search, err := es.GoodsSearch(in.KeyWord)
	if err != nil {
		return nil, fmt.Errorf("商品搜索失败")
	}
	return &goodssrv.GoodsSearchResponse{
		List: search,
	}, nil
}
